package com.example.wemedia.controller;

import com.example.wemedia.service.WmNewsService;
import com.usian.common.alibaba.GreeTextScanUtil;
import com.usian.common.alibaba.GreenImageScanUtil;
import com.usian.model.common.dtos.ResponseResult;
import com.usian.model.common.enums.AppHttpCodeEnum;
import com.usian.model.media.dtos.WmNewsDto;
import com.usian.model.media.dtos.WmNewsPageReqDto;
import com.usian.model.media.pojos.WmNews;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@Api
public class WmNewsController {
    @Autowired
    private WmNewsService wmNewsService;
    @Autowired
    private GreeTextScanUtil greeTextScanUtil;

    @GetMapping("wmnews/v1/get_all_list")
    public ResponseResult getAllList(@RequestBody WmNewsPageReqDto wmNewsPageReqDto){
        return wmNewsService.getAllList(wmNewsPageReqDto);

    }
    @PostMapping("wmnews/v1/add_wmnews")
    public ResponseResult addWmNews(@RequestBody WmNewsDto wmNewsDto) throws Exception {
        System.out.println(wmNewsDto.getContent());
        String s = greeTextScanUtil.greenTextScan(wmNewsDto.getContent());
        if (s==null){
            return ResponseResult.errorResult(AppHttpCodeEnum.PARAM_REQUIRE);
        }
        if (s.equals("pass")){
            return wmNewsService.addWmNews(wmNewsDto);
        } else if (s.equals("block")){
            return ResponseResult.errorResult(AppHttpCodeEnum.NO_FAIL);
        }else{
            return ResponseResult.errorResult(AppHttpCodeEnum.PARAM_REQUIRE);
        }
    }
    @PostMapping("wmnews/v1/del_wmnews")
    public ResponseResult delWmnews(Integer id){
        return wmNewsService.del(id);
    }

    @GetMapping("wmnews/v1/get_wmnews_by_id")
    public WmNews getWmNewsById(Integer id){
        return wmNewsService.getNewsById(id);
    }

    @PostMapping("wmmnews/v1/update_wmnews")
    public Integer updateWmNews(@RequestBody WmNews wmNews,@RequestParam Integer status){
        return wmNewsService.updateWmNews(wmNews,status);
    }
    @GetMapping("/wmnews/v1/get_checked_wmnews")
    public List<WmNews> getCheckedWmnews(){
        return  wmNewsService.getCheckedWmnews();
    }

    @PostMapping("wmnews/v1/update_wmnews")
    public Integer updateWmnews(@RequestBody WmNews wmNews){
        return wmNewsService.updateWmNew(wmNews);
    }

    @GetMapping("wmnews/v1/get_name")
    String selectName(@RequestParam Integer userId){
        return wmNewsService.selectName(userId);
    }
}
